//
//  bit_set.h
//  9.24_bloom_filter
//
//  Created by Shi HaoRan on 2023/9/24.
//

#pragma once

#include <vector>
#include <iostream>
#include <string>

using namespace std;

namespace shr
{
    template<size_t N>
    class bit_set
    {
    private:
        typedef bit_set<N> Self;
        
    public:
        bit_set()
        {
            _bitset.resize(N / 32 + 1);
        }
        
        Self& set(int x)
        {
            int i = x / 32;
            int j = x % 32;
            _bitset[i] |= 1 << j;
            return *this;
        }
        
        Self& reset(int x)
        {
            int i = x / 32;
            int j = x % 32;
            _bitset[i] &= ~(1 << j);
            return *this;
        }
        
        bool test(int x)
        {
            int i = x / 32;
            int j = x % 32;
            return _bitset[i] & (1 << j);
        }
        
        Self& flip(int x)
        {
            if(test(x)) {
                reset(x);
            }
            else {
                set(x);
            }
            return *this;
        }
        
    private:
        vector<int> _bitset;
    };
}
